const ARule = require('./ARule');

class RoundRule extends ARule {

    counterMap = new Map();

    /**
     * 通过循环规则选择一个服务节点
     * @param {String} service 
     * @param {Array<String>} nodes 
     * @returns 服务节点
     */
    choose(service, nodes) {
        let counter = this.counterMap.get(service)
        if (!counter) {
            counter = 1;
        }

        let node = nodes[counter % nodes.length];
        console.debug(`${counter} round choose : ${service} ${node}`);
        this.counterMap.set(service, ++counter);
        return node;
    }
}


module.exports = RoundRule;